/**
 * Project Name:cnsy-url-short-service
 * File Name:BatchNumberUtil.java
 * Package Name:cn.cnsy123.shorturls.business.util 
 * Date: 2020年4月6日-下午11:55:15
 * Copyright (c) 2020, yangpengfei@360@126.com All Rights Reserved. 
 *
 */

package cn.cnsy123.shorturls.business.util;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang3.time.FastDateFormat;

/**
 * ClassName: BatchNumberUtil
 * 
 * @author yangpengfei
 * @date 2020年4月6日-下午11:55:15
 * @version 1.0
 * @since JDK 1.7
 */
public class BatchNumberUtil {
    
    private static final String TIME_STAMP = "yyyyMMddHHmmssSSS";
    
    private static final String STR_SEPARATOR = "_";
    
    private static final AtomicInteger SEQ_NUMBER = new AtomicInteger(1);
    
    public synchronized static String createNewId() {
        StringBuilder batchNumber = new StringBuilder();
        batchNumber.append(FastDateFormat.getInstance(TIME_STAMP).format(System.currentTimeMillis()));
        batchNumber.append(STR_SEPARATOR);
        batchNumber.append(SEQ_NUMBER.getAndIncrement());
        return batchNumber.toString();
    }

}
